<template>
    <div >
        <div style="margin-bottom: 60px;margin-top: 140px;justify-content:center;flex-direction: row">
            <image @click="switchSel('stu')" style="width: 149px;height: 149px;margin: 20px" :src="stuSelected?'http://121.42.150.64:8099/resource/img/xs-s.jpg':'http://121.42.150.64:8099/resource/img/xs.jpg'"></image>
            <image @click="switchSel('tech')" style="width: 149px;height: 149px;margin: 20px" :src="techSelected?'http://121.42.150.64:8099/resource/img/jz-s.jpg':'http://121.42.150.64:8099/resource/img/jz.jpg'"></image>
        </div>
        <div class="login">
            <list>
                <cell>
                    <div class="cell">
                        <text class="label">账号</text>
                        <div class="input">
                            <input  v-model="username" class="input-text" placeholder="请输入账号" type="text" />
                        </div>
                    </div>
                </cell>
                <cell>
                    <div class="cell">
                        <text class="label">密码</text>
                        <div class="input">
                            <input  v-model="password" class="input-text" placeholder="请输入密码" type="password" />
                        </div>
                    </div>
                </cell>
                <cell>
                    <text @click="login()" class="btn">登录</text>
                </cell>
            </list>
        </div>
        <div style="margin-top: 120px;justify-content:center;flex-direction: row">
            <image style="width: 300px;height: 103px;" src="/resource/img/logo-s.png"></image>
        </div>
    </div>
</template>

<script>
    import mixins from '../mixins';
    const modal = weex.requireModule('modal');
    const storage = weex.requireModule('storage');

    export default {
        mixins:[mixins],
        data: function () {
          return {
                username:"",
                password:"",
                stuSelected:true,
                techSelected:false
          }
        },
        methods: {
          switchSel:function(sel){
              this.stuSelected = sel == 'stu';
              this.techSelected = sel == 'tech';

          },
          login: function (e) {

                if(this.username == ''){
                     modal.toast({ message: '帐号不能为空', duration: 0.5 });
                     return;
                }
                if(this.password == ''){
                     modal.toast({ message: '密码不能为空', duration: 0.5 });
                     return;
                }

                modal.toast({ message: '登录中...', duration: 0.5 })
                let self=this;
                self.request({
                        url:"/login",
                        type:"post",
                        data:{"username":self.username,"password":self.password}
                    }).then(res=>{
                        console.log("status:"+res.status);
                        if(res.status==1){
                            storage.setItem('access_token', res.data.access_token);
                            storage.setItem('username', res.data.username);
                            storage.setItem('userid', res.data.userid);
                            storage.setItem('name', res.data.name);
                            self.jump("/");
                        }else{
                            modal.toast({ message: '用户名或密码有误！', duration: 0.5 })
                        }
                });

          }
        }
  }
</script>
<style scoped>
    .user{
        height: 140px;
        width: 140px;
        border-color: #42b7ff;
        border-style: solid;
        border-width: 3px;
        margin: 20px;
        border-radius: 200px;
        color: #42b7ff;
        font-size: 40px;
        padding-top:30px;
        text-align: center;
    }
    .select{

    }
    .login{
        margin-left: 25px;
        margin-right: 25px;
        width: 702px;
    }
    .cell{
        width: 702px;
        margin-bottom: 20px;
        flex-direction: row;
        border-bottom-width:1px;
        border-bottom-style:solid;
        border-bottom-color: #e4e4e4;
        padding-top:15px;
        padding-bottom:15px;
    }
    .label{
        width: 120px;
        font-size: 30px;
        padding-top: 18px;
    }
    .input{
        flex: 1;
        margin-top: -4px;
    }
    .input-text{
        font-size: 30px;
        padding-top: 20px;
        padding-bottom: 20px;
        padding-right: 20px;
        color: #666666;
        border-width: 0;
        flex: 1;

    }
    .btn{
        background-color: #42b7ff;
        width: 702px;
        border-radius: 6px;
        height: 88px;
        font-size: 36px;
        margin-top: 40px;
        padding-top: 20px;
        color: #ffffff;
        text-align: center;
    }
</style>


